import { defineStore } from 'pinia'

export const useUserStore = defineStore('userStore', {
  state: () => {
    return {
      currentUrl: '' as any,
      userVisible: false as any,
      userInfo: {} as any,
      token: '' as any,
      accessArticle: [] as any,
      tab: 0 as any,
      page: 1 as any
    }
  },
  actions: {
    logout() {
      this.userInfo = {}
      this.token = ''
      this.accessArticle = []
      window.sessionStorage.removeItem('token')
    }
  },
  persist: {
    storage: window.sessionStorage
  },
  getters: {
    getUserInfo(state) {
      return state.userInfo
    },
    getToken(state) {
      return state.token
    }
  }
})